<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-10-09
 * Time: 15:47
 */

namespace App\Models;


class UserAmount extends BaseModel
{
    /**
     * 与模型关联的数据表
     *
     * @var string
     */
    protected $table = 'user_amount';

    /**
     * 主键
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 需要被转换成日期的属性。
     *
     * @var array
     */
    protected $dates = ['time'];

    /**
     * @var array
     */
    protected $hidden = ['deleted_at'];

    /**
     * @var array
     */
    protected $guarded = ['id'];

    const CASH_WITHDRAWAL = 0;
    const DEDUCT_DEPOSIT = 1;
    const ORDER = 2;
    const RECHARGE_AMOUNT = 3;
    const SURRENDER_CERTIFICATE = 4;
    const MYSELF_ACTION = 5;
    const FANS_ACTION_SUCCESS = 6;
    const UNKNOWN_STATUS = 7;
    const AUCTION_SUCCESS = 8;
    const MYSELF_ACTION_SUCCESS = 9;
    const ACTION_INCOME = 10;

    /**
     * 类型明细
     * TODO 用户加价、后台审核寄拍成功、用户支付拍卖尾款、用户充值等
     * @var array
     */
    public static $tradeTypeMap = [
        self::CASH_WITHDRAWAL   => '提现',
        self::DEDUCT_DEPOSIT   => '扣除保证金',
        self::RECHARGE_AMOUNT   => '充值',
        self::SURRENDER_CERTIFICATE   => '退保证金',
        self::MYSELF_ACTION   => '拍卖红包',
        self::FANS_ACTION_SUCCESS   => '好友成交红包',
        self::UNKNOWN_STATUS   => ' ',
        self::AUCTION_SUCCESS   => '寄拍收入',
        self::MYSELF_ACTION_SUCCESS   => '拍卖成交红包',
        self::ACTION_INCOME   => '拍卖收入',
    ];

    /**
     * @var array
     */
    protected $appends = ['trade_type_name'];

    /**
     * @return mixed
     */
    public function getTradeTypeNameAttribute(){
        return self::$tradeTypeMap[$this->tradeType];
    }

    /**
     * 明细用户
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'userId', 'id');
    }
}
